<?php
namespace Common\Controller;
use Think\Controller;
class BaseController extends Controller{
   public function _initialize() {
      /* if (!session('?name')) {
           $this->error('没有登录', U('login'));
       }else{
           $this->checkLogin();
       }*/
       $this->showMenus();
   }

    protected function getDict($field){
        $where=[
            'field'=>$field,
            'lock'=>0
        ];
        $res=M('dict')->where($where)->select();
        $this->assign($field,$res);
    }

    protected function checkLogin(){
        $url = MODULE_NAME.'/'.CONTROLLER_NAME.'/'.ACTION_NAME;
        //echo $url;exit;
        $menu = M('menus')->where(['url'=>$url])->find();
        $arrRole = explode(',',session('role'));
       // echo $arrRole;exit;
        if(in_array($menu['menu_id'],$arrRole)==false){
            exit('页面访问出错！');
        }
    }


    private function showMenus(){
        $menus = M('menus')
            ->where([
                'lock'=>1,
               // 'menu_id'=>['in',session('role')]
            ])
            ->order(['mgroup'=>'asc','msort'=>'asc'])
            ->select();
        //dump($menus);
        $this->assign('locks',$menus);
    }

    protected function getDictItems($field){
        $where = [
            'field'=>$field,
            'lock'=>0
        ];
        return $res = M('dict')->where($where)->select();
    }

}
